/* Copyright (c) 2004-2023 Peigen.info. All rights reserved. */
package info.peigen.hotpot.demo.gateway;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartboot.socket.extension.protocol.StringProtocol;
import org.smartboot.socket.transport.AioQuickClient;
import org.smartboot.socket.transport.AioSession;
import org.smartboot.socket.transport.WriteBuffer;

import java.io.IOException;

/**
 * <b>(SocketSenderClient)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024/9/2
 */
@Slf4j
public class SocketSenderClient {
    public static void main(String[] args) throws IOException, InterruptedException {
        StringProtocol protocol = new StringProtocol();
        AioQuickClient clients  = new AioQuickClient("47.109.59.83", 16770, protocol, (session, msg) -> log.info("ReceiverClient:{} 收到Push消息:{}", session.getSessionID(), msg));
        AioSession     session  = clients.start();
        byte[]         msg      = "HelloWorld".getBytes();
        while (true) {
            WriteBuffer writeBuffer = session.writeBuffer();
            writeBuffer.writeInt(msg.length);
            writeBuffer.write(msg);
            writeBuffer.flush();
            Thread.sleep(1000);
        }
    }
}
